import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  ManyToOne,
  Unique,
} from 'typeorm';
import { User } from '../user/user.entity';
import { Song } from '../song/song.entity';

@Entity()
@Unique(['userId', 'songId'])
export class UserSong {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  userId: number;

  @Column()
  songId: number;

  @Column({ default: false })
  isFavorite: boolean;

  @Column({ default: 0 })
  playCount: number;

  @CreateDateColumn()
  addedAt: Date;

  @UpdateDateColumn()
  updatedAt: Date;

  @Column({ nullable: true })
  lastPlayedAt: Date;

  @ManyToOne(() => User, (user) => user.id)
  user: User;

  @ManyToOne(() => Song, (song) => song.id)
  song: Song;
}
